package com.net.xpay.stat.scheduler;


import com.net.xpay.stat.task.PartnerCombinationSettleDailyTask;
import com.net.xpay.common.helper.NoticeHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 2019/7/15 16:28

 * 批量有密、安全发统一统计合伙人佣金
 */
@Slf4j
@Component
public class PartnerCombinationSettleScheduler {


    @Autowired
    private PartnerCombinationSettleDailyTask partnerCombinationSettleDailyTask;

    @Autowired
    private NoticeHelper noticeHelper;



    /**
     * 合伙人佣金统计
     */
    @Scheduled(cron = "1 0 0 * * *")
    public void doPartnerCombinationSettleDailyTask() {
        try {
            long t1 = System.currentTimeMillis();
            log.info("start schedule doPartnerCombinationSettleDailyTask|now={}", LocalDateTime.now());
            partnerCombinationSettleDailyTask.startDailyWork();
            long t2 = System.currentTimeMillis();
            log.info("end schedule doPartnerCombinationSettleDailyTask|now={}|cost={}", LocalDateTime.now(), t2 - t1);
            noticeHelper.sendSystemInfoNotice("合伙人统一业务佣金统计完成，耗费时间：" + (t2 - t1), "text");
        } catch (Throwable e) {
            log.warn("doPartnerCombinationSettleDailyTask error", e);
            noticeHelper.sendSystemMonitorNotice("合伙人统一业务佣金统计失败|doPartnerCombinationSettleDailyTask error", "text");
        }
    }


}
